<template>
  <div>
    <div style="background-color: #fff; height: 500px">
      <p style="font-size: 20px; margin: 10px 0 0 10px; padding: 20px">
        专题基础信息
      </p>
      <div style="margin-left: 70px">
        <p style="margin-top: 10px">
          专题名称：<el-input
            v-model="name"
            style="width: 240px"
            placeholder="请输入内容"
          />
        </p>
        <br />
        <p style="margin-top: 10px">
          专题描述：<el-input
            v-model="content"
            style="width: 400px"
            placeholder="请输入内容"
          />
        </p>
        <br />
        <p style="margin-top: 10px">
          相关单品：<el-input
            v-model="num"
            style="width: 240px"
            placeholder="请输入单品"
          />
        </p>
        <br />
        <p style="margin-top: 10px">
          发布时间：<el-date-picker
            v-model="date"
            type="date"
            placeholder="请选择时间"
            style="width: 400px"
          />
        </p>
        <br />
        <p style="margin-top: 10px">
          专题状态：<el-radio v-model="qijin" name="yong" :value="true"
            >正常</el-radio
          >
          <el-radio v-model="qijin" name="yong" :value="false">禁用</el-radio>
        </p>
        <br />
        <div style="margin-top: 10px; margin-left: 50px">
          <el-button @click="edit">编辑</el-button>
          <el-button @click="reset">取消</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
  
  <script setup lang="ts">
import { ref, onMounted } from "vue";
import axios from "axios";
import { useRoute,useRouter } from "vue-router";
const route = useRoute();
const router =useRouter();
const name = ref("");
const content = ref("");
const qijin = ref<Boolean>();
const date = ref("");
const num = ref("");
const _id = route.query._id;
const getlist = async () => {
  await axios.get(`http://localhost:3000/zjm/hui?_id=${_id}`).then((res) => {
    console.log(res.data.list);
    let data = res.data.list;
    data.forEach((item: any) => {
      name.value = item.name;
      content.value = item.content;
      qijin.value = item.flag;
      date.value = item.time;
      num.value = item.num;
    });
  });
};
const edit = async () => {
  let data = {
    name: name.value,
    content: content.value,
    flag: qijin.value,
    time: date.value,
    num: num.value,
    _id: _id,
  }
  await axios.post(`http://localhost:3000/zjm/editsman`, data).then((res) => {
    console.log(res.data);
    
    getlist()
  });
  router.push('/index/specialmanagement')
};
onMounted(() => {
  getlist();
});
const reset = async () => {};
</script>
  
  <style scoped>
</style>